package com.veeder.datacollection.config;

import java.net.InetSocketAddress;

import com.veeder.datacollection.exception.ConfigurationException;

public class ConnectionParam {

	public static enum ConnectionMode {
		TCPIP, SerialCommunication
	}

	private ConnectionMode mode;
	private InetSocketAddress hostSocketAddress;
	private SerialPortParam serialParam;

	public ConnectionMode getMode() {
		return mode;
	}

	public ConnectionMode setMode(String modeStr) throws ConfigurationException {
		ConnectionMode mode=parseMode(modeStr);
		this.mode=mode;
		return mode;
	}
	
	public static ConnectionMode parseMode(String modeStr) throws ConfigurationException{
		ConnectionMode mode =null;
		try 
		{
			int modeNumber = Integer.parseInt(modeStr);
			mode= ConnectionMode.values()[modeNumber];
		} catch (Exception e) {
			throw new ConfigurationException("mode config error", e);
		}
		
		return mode;
		
	}

	public InetSocketAddress getHostSocketAddress() {
		return hostSocketAddress;
	}

	public void setHostSocketAddress(InetSocketAddress hostSocketAddress) {
		this.hostSocketAddress = hostSocketAddress;
	}

	public SerialPortParam getSerialParam() {
		return serialParam;
	}

	public void setSerialParam(SerialPortParam serialParam) {
		this.serialParam = serialParam;
	}
}